﻿<?php if( ! defined('BASEPATH')) exit('No direct script access allowed');
/********************
 *@param function:OplusCms 前臺 頁面管理
 *@param datetime 2012-01-05
 *@param author solgh
 ********************/
require APPPATH.'/libraries/REST_Controller.php';
class Service extends REST_Controller{
    /*登陸接口*/
	public function login_get(){

		$username = $this->input->get_post("username");
		$password = $this->input->get_post("password");
        if(empty($username) || empty($password)){
            $this->response(array('error' => '請輸入用戶名和密碼!','status'=>0), 200);
        }
        $this->load->model('admins_mdl');
        $query = $this->admins_mdl->get_user_admin($username,md5($password));
        if ($query) {
            $token = md5(time().$query['id']);
            $this->admins_mdl->edit_admins(array('token' => $token), $query['id']);

            $user = array(
                'username' => $query['login_name'],
                'accountID' => $query['id'],
                'groupID'=>$query['group_id'],
                'token' => $token,
	        'status'=>1
            );
        }
        if(isset($user)&&$user){
            $this->nsession->set_userdata($user);
            $this->response($user, 200);
        }else{
            $this->response(array('error' => '賬戶不存在或賬戶密碼不正確!','status'=>0), 200);
        }
	}
}